<%@page language="java" pageEncoding="UTF8"%>
<%@page import="javax.servlet.ServletOutputStream"%>
<%@page import="jxl.*"%>
<%@page import="jxl.write.*"%>

<%
	java.sql.Connection conn = cn.dlbj.util.DBUtil.getConnection();
	java.sql.Statement stmt = conn.createStatement();
	String sql = "select xm,sjh,email,invite_code,state,tjr,vnumber,show_name from z_ryhy_zk where frozen='N' and email_sent_info='发送邀请邮件成功'";
	java.sql.ResultSet rs = stmt.executeQuery(sql);
	
	response.setContentType("application/download");
	response.setHeader("Content-Disposition","attachment;filename=invitedMemebers.xls");
	
	WritableCellFormat contentFromart = new WritableCellFormat(NumberFormats.TEXT);
	WritableCellFormat cellFormat=new WritableCellFormat();  //换行功能
	cellFormat.setAlignment(jxl.format.Alignment.LEFT);
	cellFormat.setWrap(true);
	
	ServletOutputStream sos = response.getOutputStream();
	WritableWorkbook wwb=null;
	wwb = Workbook.createWorkbook(sos);
  	WritableSheet ws = wwb.createSheet("sheet1", 0);
  	
   	Label lab = new Label(0, 0, "姓名");
   	ws.addCell(lab);
   	lab = new Label(1, 0, "卡号");
   	ws.addCell(lab);
   	lab = new Label(2, 0, "是否激活");
   	ws.addCell(lab);
   	lab = new Label(3, 0, "是否显示姓名");
   	ws.addCell(lab);
   	lab = new Label(4, 0, "手机号");
   	ws.addCell(lab);
   	lab = new Label(5, 0, "电子邮件");
   	ws.addCell(lab);
   	lab = new Label(6, 0, "推荐人");
   	ws.addCell(lab);
   	lab = new Label(7, 0, "邀请码");
   	ws.addCell(lab);
    
   	int row = 1;
   	while(rs.next()) {
   		lab = new Label(0, row, rs.getString("xm"));
   		ws.addCell(lab);
   	   	lab = new Label(1, row, rs.getString("vnumber"));
   	   	ws.addCell(lab);
   	   	lab = new Label(2, row, rs.getInt("state") == 0 ? "否" : "是");
   	   	ws.addCell(lab);
   	   	lab = new Label(3, row, rs.getInt("state") == 0 ? "否" : "是");
   	   	ws.addCell(lab);
   	   	lab = new Label(4, row, rs.getString("sjh"));
   	   	ws.addCell(lab);
   	   	lab = new Label(5, row, rs.getString("email"));
   	   	ws.addCell(lab);
   	   	lab = new Label(6, row, rs.getString("tjr"));
   	   	ws.addCell(lab);
   	   	lab = new Label(7, row, rs.getString("invite_code"));
   	   	ws.addCell(lab);
   		row++;
   	}
    conn.close();
   	wwb.write();
   	wwb.close();
   	sos.flush();
   	sos.close();
   	out.clear(); 
   	out = pageContext.pushBody();
%>